//
//  ZSRegistViewController.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/10/29.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSRegistViewController.h"
#import "ZSRegistDocViewController.h"
#import "BRServiceCenter.h"

@interface ZSRegistViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *rePasswordTextField;

@end

@implementation ZSRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)submit:(id)sender {
    
    NSString *email = self.emailTextField.text;
    NSString *pwd = self.passwordTextField.text;
    NSString *repwd = self.rePasswordTextField.text;
    if ([email isEqualToString:@""]) {
        [self br_AutoDisappearWithText:@"邮箱不能为空"];
        return;
    }
    if ([pwd isEqualToString:@""]) {
        [self br_AutoDisappearWithText:@"密码不能为空"];
        return;
    }
    
    if (![pwd isEqualToString:repwd]) {
        [self br_AutoDisappearWithText:@"两次输入密码不一致"];
        return;
    }
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params hs_setSafeValue:@"email" forKey:@"type"];
    [params hs_setSafeValue:email forKey:@"name"];
    [params hs_setSafeValue:pwd forKey:@"value"];
    
    [self br_progressHUD:YES];
    [BRServiceCenter BRServiceCenterUPDWithAction:@"register" CMD:[BRCommand CommandRegist] params:params response:^(BRMessageResponseType type, NSInteger retryCount, id responseObj) {
        if (responseObj) {
            [self br_progressHUD:NO];
            BRUDPResponse *response = responseObj;
            if ([response.state isEqualToString:@"0001"]) {
                [self br_alertViewWithTitle:@"提示" content:@"邮件已经发送，请进入邮箱激活帐户！" operationIndex:^(NSInteger clickedIndex) {
                    [self.navigationController popViewControllerAnimated:YES];
                }];
            }else
            {
                [self br_AutoDisappearWithText:response.stateDesc];
            }
        }
    }];
}

- (IBAction)readDoc:(id)sender {
    [self br_pushViewControllerWithClassName:@"ZSRegistDocViewController"];
}

@end
